home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr46 / strx221.zip / REGX.CPP < prev    next >
Text File  |  1993-03-08  |  1KB  |  70 lines

  1. //
  2. // regx.cpp     : Define implementation for regular expression class
  3. // Author       : Roy S. Woll
  4. //
  5. // Copyright (c) 1993 by Roy S. Woll
  6. // You may distribute this source freely as long as you leave all files
  7. // in their original form, including the copyright notice as is.
  8. //
  9. //
  10. // Version 2.1      12/10/92
  11. //    Add copy constructor
  12. //
  13. // Version 2.00     11/31/92
  14. //    Define class for regular expressions.
  15. //
  16.  
  17. #include <iostream.h>
  18. #include "regX.h"
  19. #include "regximp.h"
  20.  
  21. regXimp::regXimp(void):compiledPattern(256){
  22.    error = 1;
  23.    caseSensitive=1;
  24.    startMatch=endMatch=0;
  25. };
  26.  
  27.  
  28. regX::regX(void):imp(new regXimp()){};
  29.  
  30. regX::regX(const regX& r):imp(new regXimp())
  31. {
  32.    *imp = *r.imp;
  33. };
  34.  
  35. regX::regX(const char * regexp):imp(new regXimp())
  36. {
  37.    imp->makepat(regexp);
  38. };
  39.  
  40. regX::~regX(void){ delete imp;};
  41.  
  42. regX& regX::operator=(const char * regexp){
  43.    return *this = regX(regexp);
  44. };
  45.  
  46. regX& regX::operator=(const regX& r){
  47.    *imp = *r.imp;
  48.    return *this;
  49. };
  50.  
  51.  
  52. int regX::index(const char * s, int * matchLenPtr, int start,
  53.                     int p_caseSensitive) const
  54. {
  55.    if (error()) return -1;
  56.  
  57.    if ( imp->matchs(s+start, p_caseSensitive) ){
  58.       *matchLenPtr = imp->endMatch - imp->startMatch +1;
  59.       return imp->startMatch - s;
  60.    }
  61.    else {
  62.       *matchLenPtr = 0;
  63.       return -1;
  64.    };
  65. };
  66.  
  67. int regX::error(void) const{ return imp->error; };
  68.  
  69.  
  70.